﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Data;
using System.Text;
using ihongma.Common;

namespace ihongma.Web.UI.Page
{
    public partial class search : Web.UI.BasePage
    {
        protected int page;         //当前页码
        protected string keyword = string.Empty; //关健字
        protected int totalcount;   //OUT数据总数
        protected int type = 0;
        /// <summary>
        /// 重写虚方法,此方法将在Init事件前执行
        /// </summary>
        protected override void ShowPage()
        {
            page = DTRequest.GetQueryInt("page", 1);
            keyword = DTRequest.GetQueryString("keyword").Replace("'", "");
        }

        /// <summary>
        /// 查询数据
        /// </summary>
        protected List<Model.article> get_search_list(int _pagesize, out int _totalcount)
        {
            List<Model.article> list = SearchHelper.GetInstance().SearchIndex(keyword, _pagesize, page, out _totalcount);

            if (list.Count > 0)
            {
                for (int i = 0; i < list.Count; i++)
                {
                    list[i].link_url = get_url_rewrite(list[i].channel_id.ToString(), Convert.ToInt32(list[i].id));
                }
            }
            return list;
        }

        //查找匹配的URL
        private string get_url_rewrite(string channel_id, int id)
        {
            BLL.url_rewrite bll = new BLL.url_rewrite();
            Model.url_rewrite model = bll.GetInfo(channel_id, "detail");
            if (model != null)
            {
                return linkurl(model.name, id);
            }
            return "";
        }

    }
}
